<template>
<uni-shadow-root class="goods-category-components-c-sidebar-c-sidebar-item-index"><view class="c-sidebar-item-container">
  <view :class="'c-sidebar-item '+(selected ? 'active' : '')+' '+(disabled ? 'disabled' : '')+' '+(topRightRadius ? 'top-right-radius' : '')+' '+(bottomRightRadius ? 'bottom-right-radius' : '')+' custom-class'" hover-class="c-sidebar-item--hover" hover-stay-time="70" @click="onClick">
    <view class="c-sidebar-item__text text-overflow"> {{ title }} </view>
  </view>
</view></uni-shadow-root>
</template>

<script>

global['__wxVueOptions'] = {components:{}}

global['__wxRoute'] = 'goods-category/components/c-sidebar/c-sidebar-item/index'
Component({
  relations: {
    '../../c-sidebar/index': {
      type: 'ancestor',
      linked(target) {
        this.parent = target;
      },
    },
  },

  externalClasses: ['custom-class'],
  properties: {
    title: String,
    disabled: Boolean,
  },

  data: {
    topRightRadius: false,
    bottomRightRadius: false,
  },

  methods: {
    setActive(selected) {
      return this.setData({ selected });
    },
    onClick() {
      const { parent } = this;

      if (!parent || this.properties.disabled) {
        return;
      }

      const index = parent.children.indexOf(this);

      parent.setActive(index).then(() => {
        this.triggerEvent('click', index);
        parent.triggerEvent('change', { index });
      });
    },
    setTopRightRadius(val) {
      return this.setData({
        topRightRadius: val,
      });
    },
    setBottomRightRadius(val) {
      return this.setData({
        bottomRightRadius: val,
      });
    },
  },
});
export default global['__wxComponents']['goods-category/components/c-sidebar/c-sidebar-item/index']
</script>
<style platform="mp-weixin">
.c-sidebar-item {
  display: flex;
  justify-content: center;
  text-align: center;
  background-color: #f5f5f5;
  color: #222427;
  padding: 20rpx 0;
  font-size: 26rpx;
}

.c-sidebar-item.active {
  position: relative;
  background: white;
}

.c-sidebar-item.active::before {
  content: '';
  position: absolute;
  width: 6rpx;
  height: 48rpx;
  background-color: #fa4126;
  left: 0;
  top: 50%;
  transform: translate(0, -50%);
  border-radius: 64rpx;
}

.c-sidebar-item__text {
  width: 136rpx;
  height: 36rpx;
  padding: 8rpx 0;
  line-height: 36rpx;
  text-align: center;
  font-size: 28rpx;
  color: #666666;
}

.c-sidebar-item.active .c-sidebar-item__text {
  background-color: white;
  border-radius: 36rpx;
  color: #fa4126;
}

.text-overflow {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-right-radius {
  border-top-right-radius: 16rpx;
}

.bottom-right-radius {
  border-bottom-right-radius: 16rpx;
}

.c-sidebar-item-container {
  background-color: white;
}
</style>